﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using BuXiaChu.OrderDishes.BLL.WebRuntime;
using BuXiaChu.OrderDishes.Model;
using BuXiaChu.OrderDishes.BLL;

namespace BuXiaChu.OrderDishes.Web.Admin.Sys
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Roles1 : HttpHandlerBase, IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            base.Init(context);
            var type = Request.Form["t"];
            switch (type)
            {
                case "2":
                    Add();
                    break;
                case "3":
                    Update();
                    break;
                default: break;
            }
        }

        private void Add()
        {
            #region
            AjaxActionResult result = new AjaxActionResult();
            var name = GetFormValue("name");

            if (string.IsNullOrEmpty(name) == false)
            {
                RolesModel entity = new RolesModel();
                entity.Name = name;
                entity.ApplicationId = new Guid(GetFormValue("appId"));
                entity.Description = GetFormValue("desc");

                result.success = RolesManager.Save(entity);
            }
            SerializeDataToResponseStream(result);
            #endregion
        }

        private void Update()
        {
            #region
            AjaxActionResult result = new AjaxActionResult();
            var name = GetFormValue("name");
            if (string.IsNullOrEmpty(name) == false
                && string.IsNullOrEmpty(GetFormValue("id")) == false
                && string.IsNullOrEmpty(GetFormValue("appId")) == false)
            {
                RolesModel entity = new RolesModel();
                entity.RoleId = new Guid(GetFormValue("id"));
                entity.Name = name;
                entity.ApplicationId = new Guid(GetFormValue("appId"));
                entity.Description = GetFormValue("desc");

                result.success = RolesManager.Save(entity);
            }
            SerializeDataToResponseStream(result);
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
